<?php
/**
 * 游戏大区列表
 *
 * @author xiemaomao@iwgame.com
 * @copyright Copyright (c) 2009 Green Shore (http://www.iwgame.com)
 * @version $Id: GameZone.php 1063 2011-11-22 02:03:00Z mmxie $
 */
class IG_View_Helper_GameZone extends Zend_View_Helper_Abstract
{
    /**
     * 获取游戏列表
     * @return array
     */
    public function gameZone(array $maps, array $options = array(),
        array $attrs = array(), $product = PRODUCT)
    {
        $options += array(
            'value'  => 'name',
            'title'  => 'title',
        );

        $selectOptions = array(
            array('' => '--请选择大区--'),
            array('' => '--请选择组--')
        );
        //$products = IG_Product::getInstance()->getProducts();
        //foreach ($products as $product) {
        //    $selectOptions[$product->{$options['value']}] = $product->{$options['title']};
        //}
        $html = ''; $names = array();
        foreach ($maps as $name => $value) {
            $names[] = '#' . $name;
            $html .= $this->view->formSelect($name, null,
                                             array('selected' => $value) + $attrs,
                                             array_shift($selectOptions));
        }
        $script = '$(function (){
            $.getJSON("/cache/' . $product . '.config.json", function (data){
                $("' . implode(',', $names) . '", navTab.getCurrentPanel()).linkage({
                    data:data,
                    valueKey: "' . $options['value'] . '"
                });
            });
        });';

        $this->view->headScript()
                   ->appendFile('/scripts/jquery/jquery.linkage.js')
                   ->appendScript($script);
        return $html;
    }
}